package com.sitech.ibnms.c3p.service;

import com.sitech.ibnms.c3p.Application;
import com.sitech.ibnms.c3p.domain.ResourceAccount;
import com.sitech.ismp.messageObject.cc.CccpResults;
import org.apache.ignite.services.ServiceContext;
import request.ScriptRequest;

import java.util.Map;

/**
 * Created by leo on 16/3/1.
 * 脚本执行   Ignite的服务，实际服务在类里面 ，只是通过Ignite封装发布用
 * Ignite有自己的协议，通过接口 判断 调哪个服务，用哪个方法
 * 内部使用Ignite服务，外部使用http rest服务
 * 实现方式可更换 ，通过接口编程  可以轻松改为dubbo协议
 *  Ignite需要保证 发布的服务是可序列化的
 *  Application.getBean得到spring容器里的bean，得到世界service
 *  execute是发布后执行的，通过发布后，Application.getBean得到各自的spring容器里的bean
 *  包装的目的是可以成功的通过Ignite将spring创建的服务发布出去
 */
public class IgniteScriptExecutorImpl extends IgniteService implements ScriptExecutor {

    private ScriptExecutor executor;

    @Override
    public void execute(ServiceContext ctx) throws Exception {
        super.execute(ctx);
        executor = Application.getBean(ScriptExecutor.class);
    }

    @Override
    public CccpResults executeScript(ScriptRequest req) {
        return executor.executeScript(req);
    }

    @Override
    public CccpResults executeScript(ScriptRequest req, Map<String, String> context) {
        return executor.executeScript(req, context);
    }

    @Override
    public CccpResults executeScript(ScriptRequest req, ResourceAccount resourceAccount, Map<String, String> context) {
        return executor.executeScript(req, resourceAccount, context);
    }
    @Override
    public CccpResults executeSql(ScriptRequest req, ResourceAccount resourceAccount, Map<String, String> context) {
        return executor.executeScript(req, resourceAccount, context);
    }
}
